<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- CSRF元数据 -->
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header" th:content="${_csrf.headerName}"/>
    <meta name="_csrf_parameter" th:content="${_csrf.parameterName}"/>
    <title>安全检查管理 - 哈尔滨双城区农产品物流园管理系统</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/datatables/1.10.21/css/dataTables.bootstrap4.min.css">
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        .content-header {
            margin-bottom: 20px;
        }
        .inspection-container {
            padding: 20px;
        }
        .action-btn {
            margin-right: 5px;
        }
        .dataTables_wrapper {
            padding: 0;
        }
        .form-group.required .control-label:after {
            content: "*";
            color: red;
        }
        .modal-footer {
            justify-content: space-between;
        }
        .status-pending {
            color: #dc3545;
            font-weight: bold;
        }
        .status-processing {
            color: #ffc107;
            font-weight: bold;
        }
        .status-resolved {
            color: #28a745;
        }
        .safety-index {
            font-size: 2.5rem;
            font-weight: bold;
        }
        .safety-index-high {
            color: #28a745;
        }
        .safety-index-medium {
            color: #ffc107;
        }
        .safety-index-low {
            color: #dc3545;
        }
    </style>
</head>
<body>
    <div class="inspection-container">
        <!-- 内容头部 -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0"><i class="fas fa-shield-alt mr-2"></i>安全检查管理</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#" onclick="parent.loadContent('dashboard')">首页</a></li>
                            <li class="breadcrumb-item active">安全检查管理</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <!-- 主要内容 -->
        <div class="container-fluid">
            <!-- 安全统计卡片 -->
            <div class="row mb-4">
                <div class="col-md-3">
                    <div class="card bg-info">
                        <div class="card-body">
                            <h5 class="card-title">总巡检次数</h5>
                            <p class="card-text h2" id="totalCount">加载中...</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-warning">
                        <div class="card-body">
                            <h5 class="card-title">异常巡检</h5>
                            <p class="card-text h2" id="abnormalCount">加载中...</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-danger">
                        <div class="card-body">
                            <h5 class="card-title">待处理异常</h5>
                            <p class="card-text h2" id="pendingCount">加载中...</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-success">
                        <div class="card-body">
                            <h5 class="card-title">安全指数</h5>
                            <p class="card-text safety-index" id="safetyIndex">--</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 列表卡片 -->
            <div class="card">
                <div class="card-header">
                    <div class="row">
                        <div class="col-md-8">
                            <h3 class="card-title">安全巡检列表</h3>
                        </div>
                        <div class="col-md-4 text-right">
                            <button type="button" class="btn btn-primary" onclick="addInspection()">
                                <i class="fas fa-plus"></i> 新增巡检
                            </button>
                            <button type="button" class="btn btn-warning ml-2" onclick="exportInspectionData()">
                                <i class="fas fa-file-export"></i> 导出
                            </button>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <!-- 搜索表单 -->
                    <div class="row mb-3">
                        <div class="col-md-12">
                            <form id="searchForm" class="form-inline">
                                <div class="form-group mb-2 mr-3">
                                    <label for="searchInspectionCode" class="mr-2">巡检编号:</label>
                                    <input type="text" class="form-control" id="searchInspectionCode" placeholder="输入巡检编号">
                                </div>
                                <div class="form-group mb-2 mr-3">
                                    <label for="searchInspectionArea" class="mr-2">巡检区域:</label>
                                    <input type="text" class="form-control" id="searchInspectionArea" placeholder="输入巡检区域">
                                </div>
                                <div class="form-group mb-2 mr-3">
                                    <label for="searchInspectionType" class="mr-2">巡检类型:</label>
                                    <select class="form-control" id="searchInspectionType">
                                        <option value="">全部</option>
                                        <option value="1">日常巡检</option>
                                        <option value="2">安全巡检</option>
                                        <option value="3">专项巡检</option>
                                    </select>
                                </div>
                                <div class="form-group mb-2 mr-3">
                                    <label for="searchResult" class="mr-2">巡检结果:</label>
                                    <select class="form-control" id="searchResult">
                                        <option value="">全部</option>
                                        <option value="0">正常</option>
                                        <option value="1">异常</option>
                                    </select>
                                </div>
                                <div class="form-group mb-2 mr-3">
                                    <label for="searchStatus" class="mr-2">处理状态:</label>
                                    <select class="form-control" id="searchStatus">
                                        <option value="">全部</option>
                                        <option value="0">待处理</option>
                                        <option value="1">处理中</option>
                                        <option value="2">已处理</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-primary mb-2 mr-2" onclick="searchInspection()">
                                    <i class="fas fa-search"></i> 搜索
                                </button>
                                <button type="button" class="btn btn-secondary mb-2" onclick="resetSearch()">
                                    <i class="fas fa-sync-alt"></i> 重置
                                </button>
                            </form>
                        </div>
                    </div>

                    <!-- 数据表格 -->
                    <div class="table-responsive">
                        <table id="inspectionTable" class="table table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>巡检编号</th>
                                    <th>巡检区域</th>
                                    <th>巡检人员</th>
                                    <th>巡检时间</th>
                                    <th>巡检类型</th>
                                    <th>巡检结果</th>
                                    <th>处理状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <!-- 数据将通过Ajax加载 -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 巡检编辑模态框 -->
    <div class="modal fade" id="inspectionModal" tabindex="-1" role="dialog" aria-labelledby="inspectionModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="inspectionModalLabel">新增巡检</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="inspectionForm">
                        <input type="hidden" id="inspectionId" name="inspectionId">
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="inspectionCode">巡检编号</label>
                                <input type="text" class="form-control" id="inspectionCode" name="inspectionCode" readonly>
                                <small class="form-text text-muted">系统自动生成</small>
                            </div>
                            <div class="form-group required col-md-6">
                                <label for="inspectionArea" class="control-label">巡检区域</label>
                                <input type="text" class="form-control" id="inspectionArea" name="inspectionArea" required>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group required col-md-6">
                                <label for="inspector" class="control-label">巡检人员</label>
                                <input type="text" class="form-control" id="inspector" name="inspector" required>
                            </div>
                            <div class="form-group required col-md-6">
                                <label for="inspectionTime" class="control-label">巡检时间</label>
                                <input type="datetime-local" class="form-control" id="inspectionTime" name="inspectionTime" required>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group required col-md-6">
                                <label for="inspectionType" class="control-label">巡检类型</label>
                                <select class="form-control" id="inspectionType" name="inspectionType" required>
                                    <option value="">请选择巡检类型</option>
                                    <option value="1">日常巡检</option>
                                    <option value="2">安全巡检</option>
                                    <option value="3">专项巡检</option>
                                </select>
                            </div>
                            <div class="form-group required col-md-6">
                                <label for="inspectionResult" class="control-label">巡检结果</label>
                                <select class="form-control" id="inspectionResult" name="inspectionResult" required>
                                    <option value="">请选择巡检结果</option>
                                    <option value="0">正常</option>
                                    <option value="1">异常</option>
                                </select>
                            </div>
                        </div>
                        <div id="problemSection" style="display: none;">
                            <div class="form-group required">
                                <label for="problemDesc" class="control-label">问题描述</label>
                                <textarea class="form-control" id="problemDesc" name="problemDesc" rows="3"></textarea>
                            </div>
                            <div class="form-group">
                                <label for="solution">解决方案</label>
                                <textarea class="form-control" id="solution" name="solution" rows="3"></textarea>
                            </div>
                            <div class="form-group required">
                                <label for="status" class="control-label">处理状态</label>
                                <select class="form-control" id="status" name="status">
                                    <option value="0">待处理</option>
                                    <option value="1">处理中</option>
                                    <option value="2">已处理</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="remark">备注</label>
                            <textarea class="form-control" id="remark" name="remark" rows="2"></textarea>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" id="deleteBtn" onclick="confirmDelete()" style="display:none;">
                        <i class="fas fa-trash-alt"></i> 删除
                    </button>
                    <div>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" onclick="saveInspection()">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 确认删除模态框 -->
    <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="deleteModalLabel">确认删除</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>确定要删除这条巡检记录吗？此操作不可恢复。</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-danger" onclick="deleteInspection()">确认删除</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/datatables/1.10.21/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/datatables/1.10.21/js/dataTables.bootstrap4.min.js"></script>
    <script th:src="@{/js/inspection.js}"></script>
</body>
</html> 